package client;

import java.io.File;
import java.io.FileOutputStream;
import java.util.UUID;

import org.junit.Test;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;

public class HttpClientTest {
	static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

	@Test
	public void saveImages() throws Exception {
		HttpRequestFactory requestFactory = HTTP_TRANSPORT
				.createRequestFactory();
		int imageSizes = 100;
		for (int i = 0; i < imageSizes; i++) {
			HttpRequest request = requestFactory
					.buildGetRequest(new GenericUrl(
							"http://select.pdgzf.com/ValidationImage.aspx"));
			HttpResponse response = request.execute();
			String imagePath = "validationImage/ValidationImage.aspx.";
			response.download(new FileOutputStream(new File(imagePath
					+ UUID.randomUUID() + ".jpg")));
		}
	}
}
